﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Shrestha.Trigraph
{
    /// <summary>
    /// Interaction logic for TriGraphFilter.xaml
    /// </summary>
    public partial class TriGraphFilter : Window
    {
        private WorkingSet working { get; set; }
        public WorkingSet Result { get; private set; }
        public TriGraphFilter(WorkingSet ws)
        {
            working = ws;
            InitializeComponent();

            this.latFrom.Text = working.MinDbLat.ToString();
            this.latTo.Text = working.MaxDbLat.ToString();
            
            this.lngFrom.Text = working.MinDbLng.ToString();
            this.lngTo.Text = working.MaxDbLng.ToString();

            this.dateFrom.SelectedDate = working.MinDbDate;
            this.dateTo.SelectedDate = working.MaxDbDate;
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void buttonFilter_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Result = Filter.GetFiltered(double.Parse(latFrom.Text), double.Parse(latTo.Text), double.Parse(lngFrom.Text), double.Parse(lngTo.Text), dateFrom.SelectedDate.Value, dateTo.SelectedDate.Value, working.IsClustered);
                this.DialogResult = true;
            }
            catch
            {
                MessageBox.Show("Error: Please enter valid range for the filters");
                latTo.Focus();
                this.DialogResult = false;
            }
        }

        private void dateFrom_SelectedDateChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            dateTo.DisplayDateStart = dateFrom.SelectedDate;
        }
    }
}
